package assetloader

import (
	"os"
	"path/filepath"

	"golang.org/x/image/font"
	"golang.org/x/image/font/opentype"
)

func NewFont(font_path string, size float64, dpi float64) (font.Face, error) {
	src, e := os.ReadFile(filepath.Clean(font_path))
	if e != nil {
		return nil, e
	}

	tt, e := opentype.Parse(src)
	if e != nil {
		return nil, e
	}

	mplusNormalFont, e := opentype.NewFace(tt, &opentype.FaceOptions{
		Size:    size,
		DPI:     dpi,
		Hinting: font.HintingFull,
	})
	if e != nil {
		return nil, e
	}

	return mplusNormalFont, nil
}
